package structural.composite.transparent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 透明模式下，方法名已经限制，文件夹便可以直接实现管理文件的方法
 */
public class TransDirectory extends ITransFile {
    private Map<String, ITransFile> m_mapFile;
    private String m_strDirName;

    public TransDirectory (String strDirName) {
        this.m_strDirName = strDirName;
        this.m_mapFile = new HashMap<String, ITransFile>();
    }

    @Override
    public void addFile(String strName, ITransFile file){
        System.out.println(this.m_strDirName + "添加了新文件: " + strName);
        this.m_mapFile.put(strName, file);
    }

    @Override
    public void removeFile(String strName){
        System.out.println(this.m_strDirName + "删除了文件: " + strName);
        this.m_mapFile.remove(strName);
    }

    @Override
    public List<ITransFile> getChild() {
        List<ITransFile> listFile = new ArrayList<ITransFile>();
        for (String strName: this.m_mapFile.keySet()) {
            listFile.add(this.m_mapFile.get(strName));
        }
        return listFile;
    }

    @Override
    public void printContent() {
        System.out.println("扫描了" + this.m_strDirName);
        for (String strName: this.m_mapFile.keySet()) {
            this.m_mapFile.get(strName).printContent();
        }
    }
}
